<script setup lang='ts'>
import { reactive } from "vue"
import { useUserStore } from "@/stores/useUserStore";
import { ElMessage } from 'element-plus'
import { useRouter } from "vue-router"

const userStore = useUserStore()
const router = useRouter()

defineOptions({
  name: 'VLogin',
})

const loginInfo = reactive({
  account: "364",
  password: "123"
})

const handleLogin = async () => {
  const { code, msg } = await userStore.login(loginInfo)
  if (code === 2000) {
    ElMessage.success(msg)
    router.push("/home")
  } else {
    ElMessage.error(msg)
  }
}


</script>

<template>
  <div class='login-container'>
    <div class="container">
      <h2>软件设计与体系结构</h2>
      <el-form label-width="auto" :model="loginInfo" style="max-width: 600px">
        <el-form-item label="账号">
          <el-input v-model="loginInfo.account" />
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="loginInfo.password" />
        </el-form-item>
      </el-form>
      <el-button type="primary" hover-class="button-hover" @click="handleLogin">
        登录
      </el-button>
    </div>
  </div>
</template>

<style scoped lang='scss'>
.login-container {
  font-family: Arial, sans-serif;
  background-color: #f4f4f4;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
}

.container {
  background-color: #fff;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  width: 300px;
  text-align: center;
}

.container h2 {
  margin-bottom: 20px;
}

.input-group {
  margin-bottom: 15px;
}

.input-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
}

.input-group input {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

.btn {
  background-color: #28a745;
  color: #fff;
  padding: 10px 15px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
}

.btn:hover {
  background-color: #218838;
}
</style>